package com.devo.icecream.data

import android.os.Parcel
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import java.io.Serializable

data class BaseResponse<T>(
    val code: Int = 0,
    val msg: String = "",
    val total: Int = 0,
    val data: T? = null

) {
    val isSuccess: Boolean
        get() = code == 200
}

/**
 * 商品
 * @property coverPic String
 * @property id Int
 * @property ingredientStr String
 * @property menuName String
 * @property name String
 * @property salePrice Int
 * @property sort Int
 * @property spaceId Int
 * @property spaceName String
 * @property status Int
 * @property totalPrice Int
 * @property useAble Int 0:不可用 1:可用
 * @constructor
 */
data class ProductBean(
    @SerializedName("coverPic")
    val coverPic: String = "", // http://120.78.159.86:6689/file/202203/4817df372acb22f88fa48e11e438c659.png
    @SerializedName("id")
    val id: Int = 0, // 3
    @SerializedName("ingredientStr")
    val ingredientStr: String = "fdsaf，fdafdafd，fdsafdafdsa，fdafdafa", // 121
    @SerializedName("menuName")
    val menuName: String = "", // 西撇菜单
    @SerializedName("name")
    val name: String = "xxxxx", // sss
    @SerializedName("salePrice")
    val _salePrice: Int = 0, // 1
    @SerializedName("sort")
    val sort: Int = 0, // 1
    @SerializedName("spaceId")
    val spaceId: Int = 0, // 5
    @SerializedName("spaceName")
    val spaceName: String = "", // 高科技
    @SerializedName("status")
    val status: Int = 0, // 1
    @SerializedName("totalPrice")
    val _totalPrice: Int? = 0, // null
    @SerializedName("useAble")
    val useAble: Int = 0, // 1
    @SerializedName("power")
    private val _power: String? = null, // string
) : Serializable {
    val isAvailable: Boolean
        get() = useAble == 1

    val salePrice: Float
        get() = _salePrice / 100f

    val totalPrice: Float?
        get() = _totalPrice?.div(100f)

    val power: Double
        get() = _power?.toDouble() ?: 0.0

}


/**
 * 广告
 * @property id Int
 * @property picType String
 * @property picture String
 * @property remark String
 * @property sort Int
 * @property status Int
 * @property type Int
 * @constructor
 */
data class Advertising(
    @SerializedName("id")
    val id: Int = 0, // 9
    @SerializedName("picType")
    val picType: String = "", // png
    @SerializedName("picture")
    val picture: String = "", // http://120.78.159.86:6689/file/202112/7abf5fc3840784f926e57694704eb4bf.png
    @SerializedName("remark")
    val remark: String = "",
    @SerializedName("sort")
    val sort: Int = 0, // 1
    @SerializedName("status")
    val status: Int = 0, // 1
    @SerializedName("type")
    val type: Int = 0 // 1
)

/**
 * 配料
 * @property bucket String
 * @property canRepeat Int
 * @property categoryId Int
 * @property categoryName String
 * @property chooseNum Int
 * @property id Int
 * @property isMust Int
 * @property name String
 * @property num Int
 * @property picture String
 * @property power String
 * @property price Int
 * @property remark String
 * @property validFlag Int
 * @property weight Int
 * @constructor
 */
data class IngredientsBean(
    @SerializedName("bucket")
    val bucket: String = "", // string
    @SerializedName("canRepeat")
    val canRepeat: Int = 0, // 0
    @SerializedName("categoryId")
    val categoryId: Int = 0, // 0
    @SerializedName("categoryName")
    val categoryName: String = "", // string
    @SerializedName("chooseNum")
    var chooseNum: Int = 0, // 0
    @SerializedName("id")
    val id: Int = 0, // 0
    @SerializedName("isMust")
    val isMust: Int = 0, // 0
    @SerializedName("name")
    val name: String = "", // string
    @SerializedName("num")
    val num: Int = 0, // 0
    @SerializedName("picture")
    val picture: String = "", // string
    @SerializedName("power")
    private val _power: String? = null, // string
    @SerializedName("price")
    private val _price: Int = 0, // 0
    @SerializedName("remark")
    val remark: String = "", // string
    @SerializedName("validFlag")
    val validFlag: Int = 0, // 0
    @SerializedName("weight")
    val weight: Float = 0f, // 0
    @SerializedName("sort")
    val sort: Int = 0,
    @SerializedName("chose")
    var chose: Int = 0,
    @SerializedName("usable")
    var useAble: Int = 1
) : Parcelable {

    val isAvailable: Boolean
        get() = useAble == 1

    val allowRepeat: Boolean
        get() = canRepeat == 1

    val price: Float
        get() = _price / 100f

    val power: Double
        get() = _power?.toDouble() ?: 0.0

    constructor(parcel: Parcel) : this(
        parcel.readString() ?: "",
        parcel.readInt(),
        parcel.readInt(),
        parcel.readString() ?: "",
        parcel.readInt(),
        parcel.readInt(),
        parcel.readInt(),
        parcel.readString() ?: "",
        parcel.readInt(),
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readInt(),
        parcel.readString() ?: "",
        parcel.readInt(),
        parcel.readFloat(),
        parcel.readInt(),
        parcel.readInt(),
        parcel.readInt()
    )

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(bucket)
        parcel.writeInt(canRepeat)
        parcel.writeInt(categoryId)
        parcel.writeString(categoryName)
        parcel.writeInt(chooseNum)
        parcel.writeInt(id)
        parcel.writeInt(isMust)
        parcel.writeString(name)
        parcel.writeInt(num)
        parcel.writeString(picture)
        parcel.writeString(_power)
        parcel.writeInt(_price)
        parcel.writeString(remark)
        parcel.writeInt(validFlag)
        parcel.writeFloat(weight)
        parcel.writeInt(sort)
        parcel.writeInt(chose)
        parcel.writeInt(useAble)
    }

    override fun describeContents(): Int {
        return 0
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as IngredientsBean

        if (bucket != other.bucket) return false
        if (canRepeat != other.canRepeat) return false
        if (categoryId != other.categoryId) return false
        if (categoryName != other.categoryName) return false
        if (chooseNum != other.chooseNum) return false
        if (id != other.id) return false
        if (isMust != other.isMust) return false
        if (name != other.name) return false
        if (num != other.num) return false
        if (picture != other.picture) return false
        if (_power != other._power) return false
        if (_price != other._price) return false
        if (remark != other.remark) return false
        if (validFlag != other.validFlag) return false
        if (weight != other.weight) return false
        if (sort != other.sort) return false
        if (chose != other.chose) return false
        if (useAble != other.useAble) return false

        return true
    }

    override fun hashCode(): Int {
        var result = bucket.hashCode()
        result = 31 * result + canRepeat
        result = 31 * result + categoryId
        result = 31 * result + categoryName.hashCode()
        result = 31 * result + chooseNum
        result = 31 * result + id
        result = 31 * result + isMust
        result = 31 * result + name.hashCode()
        result = 31 * result + num
        result = 31 * result + picture.hashCode()
        result = 31 * result + (_power?.hashCode() ?: 0)
        result = 31 * result + _price
        result = 31 * result + remark.hashCode()
        result = 31 * result + validFlag
        result = 31 * result + weight.hashCode()
        result = 31 * result + sort
        result = 31 * result + chose
        result = 31 * result + useAble
        return result
    }

    companion object CREATOR : Parcelable.Creator<IngredientsBean> {
        override fun createFromParcel(parcel: Parcel): IngredientsBean {
            return IngredientsBean(parcel)
        }

        override fun newArray(size: Int): Array<IngredientsBean?> {
            return arrayOfNulls(size)
        }
    }


}

/**
 * 订单
 * @property actualPrice Int
 * @property coupon CouponBean
 * @property food FoodBean
 * @property orderId String
 * @property payId String
 * @property qrCodeUrl String
 * @property timeExpire String
 * @constructor
 */
data class OrderBean(
    @SerializedName("actualPrice")
    val _actualPrice: Int = 0, // 0
    @SerializedName("coupon")
    val coupon: CouponBean? = CouponBean(),
    @SerializedName("food")
    val food: FoodBean = FoodBean(),
    @SerializedName("orderId")
    val orderId: String = "", // string 优惠券
    @SerializedName("payId")
    val payId: String = "", // string
    @SerializedName("qrCodeUrl")
    val qrCodeUrl: String = "", // string
    @SerializedName("timeExpire")
    val timeExpire: String = "" // 2022-03-30T11:24:29.748Z
) {
    val actualPrice: Float
        get() = _actualPrice / 100f
}

/**
 * 优惠券
 * @property amount Int
 * @property endTime String
 * @property id Int
 * @property name String
 * @property price Int
 * @property startTime String
 * @property usedNum Int
 * @constructor
 */
data class CouponBean(
    @SerializedName("amount")
    val amount: Float = 0f, // 0
    @SerializedName("endTime")
    val endTime: String = "", // 2022-03-30T11:24:29.748Z
    @SerializedName("id")
    val id: Int = 0, // 0
    @SerializedName("name")
    val name: String = "", // string
    @SerializedName("price")
    val _price: Int = 0, // 0
    @SerializedName("startTime")
    val startTime: String = "", // 2022-03-30T11:24:29.748Z
    @SerializedName("usedNum")
    val usedNum: Int = 0 // 0
) {
    val price: Float
        get() = _price / 100f
}

/**
 * 配方
 * @property bucket String
 * @property canRepeat Int
 * @property categoryId Int
 * @property categoryName String
 * @property currInventory Int
 * @property id Int
 * @property ingredient IngredientsBean
 * @property ingredientId Int
 * @property ingredientName String
 * @property inventoryStatus Int
 * @property picture String
 * @property power String
 * @property price Int
 * @property priceY Int
 * @property processRemark String
 * @property remark String
 * @property tag String
 * @property weight Int
 * @constructor
 */
data class RecipeBean(
    @SerializedName("bucket")
    val bucket: String = "", // string
    @SerializedName("canRepeat")
    val canRepeat: Int = 0, // 0
    @SerializedName("categoryId")
    val categoryId: Int = 0, // 0
    @SerializedName("categoryName")
    val categoryName: String = "", // string
    @SerializedName("currInventory")
    val currInventory: Int = 0, // 0
    @SerializedName("id")
    val id: Int = 0, // 0
    @SerializedName("ingredient")
    val ingredient: IngredientsBean = IngredientsBean(),
    @SerializedName("ingredientId")
    val ingredientId: Int = 0, // 0
    @SerializedName("ingredientName")
    val ingredientName: String = "", // string
    @SerializedName("inventoryStatus")
    val inventoryStatus: Int = 0, // 0
    @SerializedName("picture")
    val picture: String = "", // string
    @SerializedName("power")
    val power: String = "", // string
    @SerializedName("price")
    val _price: Int = 0, // 0
    @SerializedName("priceY")
    val priceY: Int = 0, // 0
    @SerializedName("processRemark")
    val processRemark: String = "", // string
    @SerializedName("remark")
    val remark: String = "", // string
    @SerializedName("tag")
    val tag: String = "", // string
    @SerializedName("weight")
    val weight: Float = 0f, // 0
    @SerializedName("sort")
    val sort: Int = 0,
) {
    val price: Float
        get() = _price / 100f
}

data class PLCStatusBean(
    @SerializedName("buckets")
    val buckets: Map<String, Map<String, Number>> = mapOf(),   //库存2获取库存状态
    @SerializedName("machine")
    val machine: Map<String, Any> = mapOf(),//plc总运行状态 温度等信息实体类
    @SerializedName("malfunction")
    val malfunction: List<String> = listOf()
)


data class FoodBean(
    @SerializedName("coverPic")
    val coverPic: String = "", // string
    @SerializedName("id")
    val id: Int = 0, // 0
    @SerializedName("ingredients")
    val ingredients: List<IngredientsBean> = listOf(),
    @SerializedName("invalidIngredients")
    val invalidIngredients: Map<String, IngredientsBean> = mapOf(),
    @SerializedName("name")
    val name: String = "", // string
    @SerializedName("recipes")
    val recipes: List<RecipeBean> = listOf(),
    @SerializedName("salePrice")
    val _salePrice: Int = 0, // 0
    @SerializedName("sort")
    val sort: Int = 0, // 0
    @SerializedName("spaceId")
    val spaceId: Int = 0, // 0
    @SerializedName("totalPrice")
    val totalPrice: Float = 0f, // 0
    @SerializedName("validIngredients")
    val validIngredients: Map<String, IngredientsBean> = mapOf()
) {

    val salePrice: Float
        get() = _salePrice / 100f
}

data class CellLocationResponse(
    @SerializedName("address")
    val address: String = "", // 北京市朝阳区来广营地区壮家坟;溪阳东路与东湖渠路口北287米
    @SerializedName("errcode")
    val errcode: Int = 0, // 0
    @SerializedName("lat")
    val lat: String = "", // 40.00954
    @SerializedName("lon")
    val lon: String = "", // 116.486137
    @SerializedName("radius")
    val radius: String = "" // 900
)